﻿using Model.ViewModel;
using WinForm.Details;

namespace WinForm.Modules
{
    public partial class Citys : ModuleBase
    {
        /// <summary>
        /// 必须，初始数据
        /// </summary>
        public Citys():base(2)
        {
            InitializeComponent();
        }

        /// <summary>
        /// 必须
        /// </summary>
        City CurrentObject
        {
            get
            {
                if (CurrentView == null || CurrentView.FocusedRowHandle < 0) return null;
                return CurrentView.GetRow(CurrentView.FocusedRowHandle) as City;
            }
        }
        /// <summary>
        /// 必须
        /// </summary>
        public override void AddData()
        {
            //if (!IsDetailExist(Guid.Empty))
            //    ShowModuleDialog(new CompanyDetail(this.FindForm(), GetSession, null, MenuManager,
            //        CloseDetailFormAndReload));
            ChangActiveDetail(new CityAddEditDetail(this, null));
        }

        /// <summary>
        /// 必须
        /// </summary>
        public override void EditData()
        {
            //if (!IsDetailExist(CurrentCompany.Oid))
            //    ShowModuleDialog(new CompanyDetail(this.FindForm(), GetSession, CurrentCompany, MenuManager,
            //        CloseDetailForm));
            ChangActiveDetail(new CityAddEditDetail(this, CurrentObject));
        }

        /// <summary>
        /// 必须
        /// </summary>
        public override void DeleteData()
        {
            DAL.City.Delete(CurrentObject.CityId);
        }

        /// <summary>
        /// 必须
        /// </summary>
        public override void RefreshData()
        {
            ucGridControl1.DataSource = DAL.City.SelectAll();
        }
    }
}
